package com.gxa.community.customer.controller;

import com.gxa.community.core.pojo.dto.customer.dto.UserAgentApplicationDto;
import com.gxa.community.core.utils.R;
import com.gxa.community.customer.service.UserService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;


@RestController
@Log4j2
@RequestMapping("user")
//@Validated
public class UserController {

    @Autowired
    UserService userService;

    @PostMapping("/loginOut")
    public R loginOut(HttpServletRequest request){
        String token = request.getHeader("token");
        if (ObjectUtils.isEmpty(token))
            return R.error("token 异常");
        return userService.loginOut(token);
    }

    @ApiOperation("获取用户信息")
    @GetMapping("/getUserInfo")
    public R getUserInfo(HttpServletRequest request) {
        String token = request.getHeader("token");

        if (ObjectUtils.isEmpty(token))
            return R.error("获取失败");
        return userService.getUserInfo(token);
    }

    @ApiOperation("申请团长")
    @PostMapping("/agent/application")
    public R addUserApplicationAgent(@RequestBody UserAgentApplicationDto userAgentApplicationDto){
        return userService.addUserApplicationAgent(userAgentApplicationDto);
    }
}
